package com.ruoyi.system.controller;

import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.mq.config.RabbitMqConfigVo;
import com.ruoyi.system.api.domain.SysDept;
import com.ruoyi.system.service.ISysDeptService;
import io.swagger.v3.core.util.Json;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;



@RestController
@RequestMapping("/test")
public class TestController extends BaseController {
    @Autowired
    private RabbitTemplate rabbitTemplate;
    @Autowired
    private ISysDeptService deptService;
    @Autowired
    private RabbitMqConfigVo rabbitMqConfigVo;

    @PostMapping("/pushMq")
    public AjaxResult pushMq()  {
        SysDept sysDept = deptService.selectDeptById(100L);
        rabbitTemplate.convertSendAndReceive(rabbitMqConfigVo.getTestGhlExchange(),rabbitMqConfigVo.getTestGhlRouting(),Json.pretty(sysDept));
        return success(null);
    }


    @RabbitListener(queues = "${mq.queue.ghlTestQueue}")
    @RabbitHandler
    public void getGhlTestMsg(String msg) {
        System.out.println(msg);
    }
}
